<template>
    <a-divider> 发布规则 </a-divider>
    <a-space>
        <a-popconfirm title="确定操作吗?" ok-text="确定" cancel-text="取消" @confirm="confirm1">
            <a-button type="dashed" danger :loading="btnLoading">重新生成文章发布任务队列</a-button>
        </a-popconfirm>
        <a-popconfirm title="确定操作吗?" ok-text="确定" cancel-text="取消" @confirm="confirm2">
            <a-button type="primary">开启发布任务</a-button>
        </a-popconfirm>
        <a-popconfirm title="确定操作吗?" ok-text="确定" cancel-text="取消" @confirm="confirm3">
            <a-button type="dashed" danger>暂停发布任务</a-button>
        </a-popconfirm>
        <a-button type="dashed" @click="publishRuleClick1">重新载入发布接口到缓存</a-button>
    </a-space>
    <a-row></a-row>
    <br />
    <a-typography-paragraph>
        <a-typography-text mark>
            每天<a-typography-text strong>零点</a-typography-text
            >会自动生成文章发布任务队列,并把昨天剩余未发布的删除。</a-typography-text
        >
        <a-typography-text mark> 每天<a-typography-text strong>八点</a-typography-text>会自动开启发布任务。</a-typography-text
        >每天<a-typography-text strong>零点</a-typography-text>会自动载入发布接口到缓存
    </a-typography-paragraph>
    <a-typography-paragraph>
        点击暂停发布任务,此时会杀死发布进程,阻止发布,点击开启发布会接着上次继续发布。
    </a-typography-paragraph>
    <a-typography-paragraph>
        如果发布接口改变,希望立即生效,此时需要先暂停发布任务,然后点击重新载入发布接口到缓存、再开启发布任务。
    </a-typography-paragraph>
    <a-typography-paragraph> 如果发布任务正在继续,此时再点击发布任务,则是重新添加了一个新的进程。 </a-typography-paragraph>
</template>

<script lang="ts" setup>
    import { publishApiToRedis, startPublishArticle, stopPublishArticle, generareTaskQueueApi } from "@/api/scripts";
    import { message } from "ant-design-vue";
    const btnLoading = ref(false);
    const confirm1 = () => {
        btnLoading.value = true;
        generareTaskQueueApi()
            .then((res) => {
                if (res.data.code === 200) {
                    message.success("操作成功!");
                }
            })
            .catch(() => {
                message.error("服务器错误!");
            })
            .finally(() => (btnLoading.value = false));
    };
    const confirm2 = () => {
        startPublishArticle()
            .then((res) => {
                if (res.data.code === 200) {
                    message.success(res.data.msg);
                } else {
                    message.error(res.data.msg);
                }
            })
            .catch(() => {
                message.error("服务器错误!");
            });
    };
    const confirm3 = () => {
        stopPublishArticle()
            .then((res) => {
                if (res.data.code === 200) {
                    message.success("操作成功!");
                }
            })
            .catch((res) => {
                message.error(res.data.msg);
            });
    };
    const publishRuleClick1 = () => {
        publishApiToRedis()
            .then((res) => {
                if (res.data.code === 200) {
                    message.success("操作成功!");
                } else {
                    message.error(res.data.msg);
                }
            })
            .catch(() => {
                message.error("服务器错误!");
            });
    };
</script>

<style scoped lang="scss"></style>
